home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2211 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Examples of using "volatile"?
  5. Date: 19 Jan 1996 16:33:57 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Jan19093357@qcd.lanl.gov>
  8. References: <4djoj2$mr1@post.gsfc.nasa.gov> <4dm91p$bsi@info.uah.edu>
  9.     <4dnf7f$1sa@fountain.mindlink.net>
  10. NNTP-Posting-Host: qcd.lanl.gov
  11. Mime-Version: 1.0
  12. Content-Type: text
  13. In-reply-to: genew@mindlink.bc.ca's message of Fri, 19 Jan 1996 06:53:15 GMT
  14.  
  15. --text follows this line--
  16. In article <4dnf7f$1sa@fountain.mindlink.net> genew@mindlink.bc.ca
  17. (Gene Wirchenko) writes: 
  18. <snip>
  19.    >Basically, like most modifiers, volatile is a hint to the compiler
  20.    >that the value of i could change at any time, and not to take its
  21.    >value for granted.  Of course, the compiler could ignore you since
  22.    >it's only a hint, but that wouldn't be a very good compiler :)
  23.  
  24.     No, it wouldn't because it would be broken.  K&R2, used as a sub
  25.    for the Standard by those of us without $120 or so to spend on said
  26.    Standard, says on page 211 (in the indented portion at the bottom):
  27.     "The purpose of volatile is to force an implementation to
  28.    suppress optimization that could otherwise occur."
  29.     Note the word "force".
  30.  
  31. Actually, the standard does almost make it a hint (note the
  32. almost). The standard is absolutely clear that a volatile access
  33. (i.e. accessing a volatile variable) cannot be optimized away: but the
  34. meaning of `access' is left free to the implementer :-) They couldn't
  35. have done much else without going to the definition of hardware, I
  36. think. 
  37.  
  38. The intent of the standard is however clear. And I would refuse to buy
  39. a compiler which optimized my use of volatile away ... on the pretext
  40. that a nop constitues an `access'.
  41.  
  42. Cheers
  43. Tanmoy
  44. --
  45. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  46. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  47. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  48. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  49. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  50. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  51.